home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / iTunes Remote / mouse.nqc next >
Encoding:
Text File  |  2001-06-23  |  1.0 KB  |  103 lines

  1. #define DRIVE OUT_A
  2. #define STEER OUT_B
  3. #define CLICK OUT_C
  4.  
  5. #define STEER_POS SENSOR_1
  6. #define DRIVE_POS SENSOR_2
  7.  
  8. #define CLICK_DOWN_TIME 30
  9. #define CLICK_UP_TIME 20
  10.  
  11. int goal;
  12.  
  13. task main()
  14. {
  15.     SetSensor(STEER_POS, SENSOR_ROTATION);
  16.     SetSensor(DRIVE_POS, SENSOR_ROTATION);
  17.     
  18.     ClearMessage();
  19.     until(Message()==1);
  20.     
  21.     // launch
  22.     click();
  23.     click();
  24.     
  25.     Wait(100);
  26.  
  27.     // v move
  28.     goal = -4;
  29.     drive();
  30.     click();
  31.     
  32.     // h move    
  33.     goal = -28;
  34.     steer();
  35.     goal = -15;
  36.     drive();
  37.         
  38.     goal = 0;
  39.     steer();
  40.     goal = 4;
  41.     drive();
  42.         
  43.     click();
  44. }
  45.  
  46. sub drive()
  47. {    
  48.     ClearSensor(DRIVE_POS);
  49.     
  50.     if (goal < 0)
  51.     {
  52.         Fwd(DRIVE);
  53.         On(DRIVE);
  54.         until(DRIVE_POS <= goal);
  55.     }
  56.     else if (goal > 0)
  57.     {
  58.         Rev(DRIVE);
  59.         On(DRIVE);
  60.         until(DRIVE_POS >= goal);
  61.     }
  62.  
  63.     Off(DRIVE);
  64. }
  65.  
  66.  
  67. sub steer()
  68. {
  69.     int p;
  70.     
  71.     On(STEER);
  72.     while(true)
  73.     {
  74.         p = STEER_POS;
  75.         if (p == goal)
  76.         {
  77.             Off(STEER);
  78.             return;
  79.         }
  80.         else if (p > goal)
  81.         {
  82.             Fwd(STEER);
  83.         }
  84.         else
  85.         {
  86.             Rev(STEER);
  87.         }
  88.     }
  89. }
  90.  
  91. sub click()
  92. {
  93.     OnFwd(CLICK);
  94.     Wait(CLICK_DOWN_TIME);
  95.     Rev(CLICK);
  96.     Wait(CLICK_UP_TIME);
  97.     Off(CLICK);
  98. }
  99.  
  100.  
  101. sub init()
  102. {
  103. }